<?
namespace Site\Event
{
    
    class GetGallery extends \Api\AjaxEvent\Listener
    {
        /**
         * Zdarzenie wyswietlajace galerie
         * realizacji lub projektu.
         *
         * @param hash - md5(id realizacji + nazwa realizacji)
         * @param type - typ projektu         
         */
         public function __event__GetGallery()
         {
            $return = array('result'=>false);            
            
            if(array_key_exists('hash',$this->m_param) && array_key_exists('type',$this->m_param))
            {                
                $hash = $this->m_param['hash'];
                $type = $this->m_param['type'];
             
                if($type == 'R' || $type == 'P')
                {
                    $view = new \Api\View\Content(array(), \Api\Config::$param);
                
                    if($type == 'R')
                    {
                        $rel = new \Site\Model\Realisation($this->m_config);                        
                        $r = $rel->getRealisationByHash($this->m_param['hash']);                
                    }else
                    {
                        $rel = new \Site\Model\Project($this->m_config);                        
                        $r = $rel->getProjectByHash($this->m_param['hash']);                
                    }
                    $r['name']=strtoupper($r['name']);
                
                    $view->realisation = $r;
                    $return['menu']  = $view->fetchTmp('menu-gallery','_shared');
                    $return['content'] = $view->fetchTmp('realisation-view');
                    $return['result'] = true;
                }
            }
            return json_encode($return);
         }
    }
}
?>